package MyGO.dao.impl;

import MyGO.dao.ICheckProDao;
import MyGO.property.CheckPro;
import MyGO.utils.FileUtils.FileIO;
import MyGO.utils.enumerastion.Department;
import com.fasterxml.jackson.core.type.TypeReference;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;

public class CheckProImpl implements ICheckProDao {
    private static List<CheckPro> CHECKPRO_LIST = new ArrayList<>();
    private static HashMap<String, CheckPro> CHECK_PR_MAP = new HashMap<>();
    static {
//        CheckPro checkPro1 =new CheckPro("JSDAYIA", "喉镜", "江南", 128.34, Department.INTERNAL);
//        CheckPro checkPro2 =new CheckPro("JSDAYIB","胃镜", "江南", 68.88, Department.INTERNAL);
//        CheckPro checkPro3 =new CheckPro("JSDAYIC","肠镜", "江南", 141.35, Department.INTERNAL);
//        CheckPro checkPro10 = new CheckPro("JSDAYID", "血检", "凉宫", 150.5, Department.INTERNAL);
//        CheckPro checkPro11 = new CheckPro("JSDAYIE", "尿检", "凉宫", 110.5, Department.INTERNAL);
//        CheckPro checkPro12 = new CheckPro("JSDAYIF", "生理性化验", "凉宫", 210.45, Department.INTERNAL);
//        CheckPro checkPro4 =new CheckPro("JKDAYIA","B超", "凉宫", 324.67, Department.SURGERY);
//        CheckPro checkPro5 =new CheckPro("JKDAYIB","手骨侧位检查", "凉宫", 34.6, Department.SURGERY);
//        CheckPro checkPro6 =new CheckPro("JKDAYIC","胸椎照影术", "凉宫", 234.22, Department.SURGERY);
//        CheckPro checkPro7 =new CheckPro("JNDAYIA","儿童血检", "芳文", 78.32, Department.PADIATRICS);
//        CheckPro checkPro8 =new CheckPro("JNDAYIB","儿童激素检查", "芳文", 156.8, Department.PADIATRICS);
//        CheckPro checkPro9 =new CheckPro("JNDAYIC","儿童健康评估", "芳文", 21.1, Department.PADIATRICS);
//
//        CHECKPRO_LIST.add(checkPro1);
//        CHECKPRO_LIST.add(checkPro2);
//        CHECKPRO_LIST.add(checkPro3);
//        CHECKPRO_LIST.add(checkPro4);
//        CHECKPRO_LIST.add(checkPro5);
//        CHECKPRO_LIST.add(checkPro6);
//        CHECKPRO_LIST.add(checkPro7);
//        CHECKPRO_LIST.add(checkPro8);
//        CHECKPRO_LIST.add(checkPro9);
//        CHECKPRO_LIST.add(checkPro10);
//        CHECKPRO_LIST.add(checkPro11);
//        CHECKPRO_LIST.add(checkPro12);
//
//        CHECK_PR_MAP.put(checkPro1.getId(), checkPro1);
//        CHECK_PR_MAP.put(checkPro2.getId(), checkPro2);
//        CHECK_PR_MAP.put(checkPro3.getId(), checkPro3);
//        CHECK_PR_MAP.put(checkPro4.getId(), checkPro4);
//        CHECK_PR_MAP.put(checkPro5.getId(), checkPro5);
//        CHECK_PR_MAP.put(checkPro6.getId(), checkPro6);
//        CHECK_PR_MAP.put(checkPro7.getId(), checkPro7);
//        CHECK_PR_MAP.put(checkPro8.getId(), checkPro8);
//        CHECK_PR_MAP.put(checkPro9.getId(), checkPro9);
//        CHECK_PR_MAP.put(checkPro10.getId(), checkPro10);
//        CHECK_PR_MAP.put(checkPro11.getId(), checkPro11);
//        CHECK_PR_MAP.put(checkPro12.getId(), checkPro12);

        TypeReference<List<CheckPro>> typeRef = new TypeReference<List<CheckPro>>() {};
        try {
            CHECKPRO_LIST = FileIO.readObjectFromJsonFile("CheckPro.json", typeRef);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        try {
            CHECK_PR_MAP = FileIO.readObjectFromJsonFile("CheckProMap.json", new TypeReference<HashMap<String, CheckPro>>() {});
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public List<CheckPro> selectAllCheckPro() {
        return CHECKPRO_LIST;
    }

    @Override
    public List<CheckPro> selectCheckProByDept(String dept) {
        return CHECKPRO_LIST.stream().filter(checkPro ->
                checkPro.getDepartment().equals(Department.parseDepartmentType(dept))).
                collect(Collectors.toList());
    }
    @Override
    public HashMap<String, CheckPro> getAllCheckPro() {
        return CHECK_PR_MAP;
    }
}

